'''
Created on Nov 21, 2011

@author: onetera
'''

from PyQt4 import QtCore , QtGui
from lib.customUI import customUI
from lib.papyDB import papyDB , tableInfo
from lib.papyDBTable import *
from insertItem import insertItemDiag

class AssmTableView(QtGui.QTableView):
    def __init__(self , parent=None):
        QtGui.QTableView.__init__(self,parent )
        self.dropRow = 0
        self.justDoubleClicked = False
        self.setAcceptDrops(True)
        self.dropEvent=1
     
#    def indexAt(self , thePoint):
#        myQPoint = QtCore.QPoint()
#        cursor = QtGui.QCursor()            
#        self.setGeometry( QtCore.QRect( pos.pos().x(), pos.pos().y()+20,260,200 ) ) 
#        myQPoint.setX( cursor.pos().x() )
#        myQPoint.setY( cursor.pos().y() )
            
#    def dropEvent(self, event):
#        print '============dropEvent=============='
#        print event.mimeData().text()
#        event.setDropAction(QtCore.Qt.CopyAction)
#        self.selectRow( int(event.mimeData().text()) )
#        event.accept()
          

class shotAssembler_UI(customUI ):
    def __init__(self,parent=None):
        QtGui.QMainWindow.__init__(self , parent)        
        customUI.__init__(self)        
        self.assemble_list = []
        self.setStyleSheet(self.styleSheet)
        self.assmTable_grp = self.grpBox("Assemble List", self.sizePolicy_prpr )
        self.assm_table = AssmTableView( self.assmTable_grp )
                   
    def createTable(self):
#        self.assmTable_grp = self.grpBox("Assemble List", self.sizePolicy_prpr )
        self.assmTable_grp.setMinimumHeight(400)
#        self.assm_table = AssmTableView( self.assmTable_grp )
#        self.assm_table = QtGui.QTableWidget( self.assmTable_grp )
        self.assm_table.setSizePolicy(self.sizePolicy_mnmn)
        self.assm_table.setMinimumHeight(150)
        self.assm_table.setFont( self.mainFont )
        self.assm_table.setGridStyle(QtCore.Qt.DashLine)        
        self.assm_table.setAlternatingRowColors(True)       
        
#        self.assm_table.setDragEnabled(True)
#        self.assm_table.setAcceptDrops(True)
        
        
        
        self.itemUP_btn = self.btn('UP')
        self.itemUP_btn.setSizePolicy( self.sizePolicy_prpr )
        
        self.insertWin_btn = self.btn('Insert')
        self.assetDelete_btn = self.btn('Delete')
        self.insertWin_btn.setMaximumSize(300, 40)        
        self.assetDelete_btn.setMaximumSize(300, 40)
        self.insertWin_btn.setMinimumHeight(40)
        
        self.insertWin_btn.setSizePolicy( self.sizePolicy_fxfx )
        self.assetDelete_btn.setSizePolicy( self.sizePolicy_fxfx )
         
        fixedSize1,fixedSize2 = 50,60              

        self.itemUP_btn.setFixedWidth(fixedSize1)                
        self.itemUP_btn.setParent( self.assmTable_grp )        
        self.itemDW_btn = self.btn('DW')
        self.itemDW_btn.setParent( self.assmTable_grp )        
        self.itemDW_btn.setFixedWidth(fixedSize1)        
        self.itemDW_btn.setSizePolicy( self.sizePolicy_prpr )
        self.assmTable_layout = QtGui.QGridLayout(self.assmTable_grp)
        self.assmTable_layout.addWidget(self.assm_table,0 , 0 , 6 ,5)
        self.assmTable_layout.addWidget(self.itemUP_btn,0 , 5 , 3 ,1)
        self.assmTable_layout.addWidget(self.itemDW_btn,3 , 5 , 3 ,1)
        self.assmTable_layout.addWidget(self.insertWin_btn,6 , 0 , 1 ,2)
        self.assmTable_layout.addWidget(self.assetDelete_btn,6 , 2 , 1 ,2)        
        
    def createAssm(self):
        fixedSize1,fixedSize2 = 150,40 
        self.assmHistory_grp , self.assmHistory_cb = self.grpCBox('Assemble History')
        self.assmClearList_btn = self.btn('Clear Assemble List')        
        self.assmClearList_btn.setFixedSize(fixedSize1,fixedSize2)
        self.assmLog_btn = self.btn('View Assemble Log')        
        self.assm_btn = self.btn('Assemble')

        self.assmLog_btn.setFixedSize(fixedSize1,fixedSize2)
        self.assm_btn.setFixedSize(fixedSize1,fixedSize2)
        self.spacer2 = QtGui.QSpacerItem( 10, 20, QtGui.QSizePolicy.Expanding,
                                    QtGui.QSizePolicy.Minimum )
#        self.assmLog_btn.setFixedHeight(40)
#        self.assm_btn.setFixedHeight(40)
        self.assmBtn_Layout = QtGui.QHBoxLayout( )
        self.assmBtn_Layout.addWidget( self.assmHistory_grp )
#        self.assmBtn_Layout.addItem( self.spacer2 )
        self.assmBtn_Layout.addWidget( self.assmClearList_btn )
        self.assmBtn_Layout.addWidget( self.assmLog_btn )
        self.assmBtn_Layout.addWidget( self.assm_btn )
        
    def setUI(self):
        self.mainWidget = QtGui.QWidget( )
        self.createPSSDcb()
        self.createTable()        
        spacer1 = QtGui.QSpacerItem( 40, 20, QtGui.QSizePolicy.Expanding,
                                    QtGui.QSizePolicy.Minimum )
        self.createAssm()        
        self.mainGridLayout = QtGui.QGridLayout( self.mainWidget )
        self.mainGridLayout.addLayout( self.PSSD_layout , 0, 0, 1, 1 )
        self.mainGridLayout.addItem( spacer1 , 0, 1, 1, 1 )        
        self.mainGridLayout.addWidget( self.assmTable_grp , 1, 0, 1, 2 )
        self.mainGridLayout.addLayout( self.assmBtn_Layout , 2, 0, 1, 1 )

        self.prj_cb.currentIndexChanged.connect( self.initSeq )
        self.seq_cb.currentIndexChanged.connect( self.initShot )
#        self.assetDelete_btn.clicked.connect( self.pressDelete )

        
        self.setCentralWidget( self.mainWidget )
        self.setWindowTitle( "Shot Assembler")
#        self.setGeometry( QtCore.QRect(50,600,405, 300) )
        
        self.show()
        
        self.initPrj()
        self.initDept()
        self.prj_cb.setCurrentIndex(1)
        self.prj_cb.setCurrentIndex(0)
        

        
    
if __name__ == '__main__':
    import sys    
    app = QtGui.QApplication(sys.argv)
    ui = shotAssembler_UI()    
    ui.setUI()
    app.exec_()
    
    
    